import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/util/ToastUtil.dart';

class ListViewWidget extends StatelessWidget {
  ListViewWidget({Key ?key, @required this.text}) : super(key: key);

  final String ?text;

  @override
  Widget build(BuildContext context) {
    //下划线widget预定义以供复用。
    Widget divider1 = Divider(
      color: Colors.blue,
    );
    Widget divider2 = Divider(color: Colors.green);
    return Scaffold(
      appBar: AppBar(
        title: Text(text??""),
      ),
      body: Container(
        alignment: Alignment.center,
        child: SingleChildScrollView(
          child: Column(
            children: [
              ListTile(title: Text("商品列表")),
              GestureDetector(
                child: SizedBox(
                  //Material设计规范中状态栏、导航栏、ListTile高度分别为24、56、56
                  height: MediaQuery.of(context).size.height - 24 - 56 - 56,
                  child: ListView.separated(
                    itemCount: 100,
                    //列表项构造器
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(title: Text("$index"));
                    },
                    //分割器构造器
                    separatorBuilder: (BuildContext context, int index) {
                      return index % 2 == 0 ? divider1 : divider2;
                    },
                  ),
                ),
                onTap: () {

                  // toArount(index, context);
                  ToastUtil.toastShort("点击~~");
                },
              ),
            ],
          ),
        )
      ),
    );
  }
}
